Skip to content

fix: repair failing tests and type errors across api and shared packages - #119

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2281-1785698467
Open

fix: repair failing tests and type errors across api and shared packages#119
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2281-1785698467

Conversation

@stooit

@stooit stooit commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Repairs all failing tests and eliminates all type errors. bun test22 pass / 0 fail; bunx tsc --noEmitclean (exit 0).

The bugs spanned both packages and matched the areas called out in the task brief.

Changes

  • Auth middleware (packages/api/src/middleware/auth.ts) — Fixed a case-sensitivity bug in the public-method allow-list ("post""POST") so POST routes are correctly treated as public. Method comparison is now normalised to uppercase to prevent this class of access-control bug from recurring.
  • Shared types (packages/shared/src/types.ts) — Renamed User.userNameusername. The unmodifiable test files (users.test.ts, auth.test.ts) use username and are the contract, so the type was wrong, not the call sites. The rename is complete across both packages.
  • Route handler (packages/api/src/routes/users.ts) — Added the missing badRequest import (already exported from ../lib/errors). This was a genuine runtime ReferenceError on the invalid-POST path, which is why "returns 400 for missing fields" failed.
  • Pagination utility (packages/shared/src/utils/pagination.ts) — Implemented the previously-stubbed paginate() against the full test contract (page slicing, total/totalPages, page/pageSize, out-of-range → empty data, empty-array handling). Also guarded against non-finite page/size via Number.isFinite so user-supplied query params can't corrupt the response (Infinity previously produced pageSize: null and zero items).
  • tsconfig.json — Referenced the already-installed bun-types ("types": ["bun-types"]) so the process global and bun:test module resolve. No new dependencies addedbun-types was already a declared devDependency.

Constraints honoured

  • No test files modified
  • No new dependencies / lockfile changes
  • Only the files the tests required were changed

Assumptions

  • username (not userName) is the canonical field name, inferred from the unmodifiable test files being the source of truth.
  • The non-finite pagination guard is a defensive hardening of the documented "safe for user-supplied params" contract; it does not change behaviour for any tested (finite) input.

Follow-ups (out of scope)

  • packages/api/src/middleware/validate.ts exports an unused requireFields() middleware duplicating inline route validation — could be consolidated.
  • The auth policy leaves POST unauthenticated (anonymous record creation). Pre-existing, deliberate, and asserted by the tests — flagged only for a future access-control decision.
  • bun-types is pinned to "latest" in package.json (pre-existing); worth pinning for reproducible builds.

- auth middleware: fix case-sensitivity bug in public-method allow-list
  ("post" -> "POST") so POST routes are correctly treated as public;
  normalise method comparison to uppercase to prevent recurrence
- shared types: rename User.userName -> username to match the API/test
  contract (test files are the source of truth and were not modified)
- routes/users: add missing badRequest import (was a runtime ReferenceError
  on the invalid-POST path)
- shared pagination: implement paginate() stub against the full test
  contract; guard against non-finite page/size (Number.isFinite) so
  user-supplied paging params can't corrupt the response
- tsconfig: reference already-installed bun-types so process/bun:test
  resolve (no new dependencies)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant